package com.zgjl.api.util;

import lombok.Getter;
import lombok.ToString;

/**
 * @description: 公共前端返回
 * @date: 2020/3/25
 * @author: yangcongzhen
 */
@ToString
@Getter
public class ResultVO<T> {

    /**
     * @Descriptio: 结果代码 S时操作成功，非S均为失败，可以根据具体的错误代码做相应处理
     */
    private String code;

    /**
     * @Descriptio: "结果消息 当结果代码非S时，把消息中的内容展示"
     */
    private String message;

    /**
     * @Descriptio: 结果数据
     */
    private T data;


    public ResultVO(String code, String message) {
        this(code, message, null);
    }

    public ResultVO(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResultVO success() {
        return success("请求成功");
    }

    public static ResultVO success(String message) {
        return success(message, null);
    }

    public static <T> ResultVO<T> success(T data) {
        return success("请求成功", data);
    }

    public static <T> ResultVO<T> success(String message, T data) {
        return new ResultVO("S", message, data);
    }


    public static ResultVO error(String code, String message) {
        return new ResultVO(code, message);
    }

    public static ResultVO error(String message) {
        return new ResultVO("E", message);
    }
}
